import flash.MovieClip;
import flash.Key;

class Bomb
{

    static function main() {
        /* var Bfield : Array<Array<MovieClip>>;
          Bfield = new Array<Array<MovieClip>>();*/
		 var Bfield = flash.Lib.current.attachMovie("Battlefield","s",1);
         var Goblin = flash.Lib.current.attachMovie("Goblin","s",2);
		 var Box = flash.Lib.current.attachMovie("Box","s",3);
		 Box._x = 80;
		 Box._y = 80;
		 Goblin._width = 40;
		 Goblin._height = 40;
       /*   for(i in 0...11)
          {
			   Bfield[i] = new Array<MovieClip>();
               for(j in 0...11)
               {
                    Bfield[i][j] = flash.Lib.current.attachMovie("mc_square","s",i*11+j);
                    Bfield[i][j]._x = i*20;
                    Bfield[i][j]._y = j*20;
					Bfield[i][j]._alpha = 50+50*((i*j)%2);
               }
          }*/
		 Goblin.onEnterFrame = function() {
			 if(Key.isDown(65)&&(Goblin._x>0)&&(Goblin._y%80==0)){
				 if((Box._x == Goblin._x-40)&&(Box._y+40>Goblin._y)&&(Box._y-40<Goblin._y))
				 {
					 if((Box._x>0)&&(Box._y%80)==0)
					 {
				         Box._x -=10;
				         Goblin._x -=10;
					 }
				 }
				 else
				 	 Goblin._x -=10;
			 }
			 if(Key.isDown(68)&&(Goblin._x<400)&&(Goblin._y%80==0)){
				 if((Box._x == Goblin._x+40)&&(Box._y+40>Goblin._y)&&(Box._y-40<Goblin._y))
				 {
					 if((Box._x<400)&&(Box._y%80==0))
					 {
				         Box._x +=10;
				         Goblin._x +=10;
					 }
				 }
				 else
				 	 Goblin._x +=10;
			  }
			  if(Key.isDown(87)&&(Goblin._y>0)&&(Goblin._x%80==0)){
				 if((Box._y == Goblin._y-40)&&(Box._x+40>Goblin._x)&&(Box._x-40<Goblin._x))
				 {
					 if((Box._y>0)&&(Box._x%80==0))
					 {
				         Box._y -=10;
				         Goblin._y -=10;
					 }
				 }
				 else
				 	 Goblin._y -=10;
			  }
			  if(Key.isDown(83)&&(Goblin._y<400)&&(Goblin._x%80==0)){
				 if((Box._y == Goblin._y+40)&&(Box._x+40>Goblin._x)&&(Box._x-40<Goblin._x))
				 {
					 if((Box._y<400)&&(Box._x%80==0))
					 {
				         Box._y +=10;
				         Goblin._y +=10;
					 }
				 }
				 else
				 	 Goblin._y +=10;
			 }
		 }
	}	
}